#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>

int main(int argc, char *argv[])
{
  if (argc < 2) {
    perror("Usage: readdir <pathname>");
    exit(1);
  }

  DIR *dp;
  struct dirent *dirent_p;

  if ((dp = opendir(argv[1])) == NULL) {
    perror("opendir");
    exit(1);
  }

  while ((dirent_p = readdir(dp)) != NULL) {
    printf("%s\n", dirent_p->d_name);
  }

  exit(0);
}
